import 'package:flutter/material.dart';

/// AnimatedSwitcher 切换控件时的动画
/// 可以自定义动画样式,默认的是改变透明度动画

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _switch = true;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Material App Bar'),
        ),
        body: Center(
            child: AnimatedSwitcher(
          duration: Duration(seconds: 1),
          child: _switch
              ? Text(
                  'Hi',
                  style: TextStyle(fontSize: 25),
                  key: UniqueKey(),
                )
              : Text(
                  'Hello',
                  style: TextStyle(fontSize: 25),
                  key: UniqueKey(),
                ),
        )),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {
              _switch = !_switch;
            });
          },
          child: Icon(Icons.add),
        ),
      ),
    );
  }
}
